import React, {Component} from "react";
import {
	View,
	Text,
} from "react-native";
var Geolocation = require("Geolocation");
export default class GeolocationExam extends Component {
	constructor(props) {
		super(props);
	}
	_onPress() {
		Geolocation.getCurrentPosition(location => {
			let result = "速度" + location.coords.speed +
				"\n经度：" + location.coords.longitude +
				"\n纬度：" + location.coords.latitude +
				"\n准确度：" + location.coords.accuracy +
				"\n行进方向：" + location.coords.heading +
				"\n海拔：" + location.coords.altitude +
				"\n海拔准确度：" + location.coords.altitudeAccuracy +
				"\n时间戳：" + location.timestamp;
			alert(result);
		}, error => {
			alert("获取位置失败:" + error.message)
		})

	}
	render() {
		return (
			<View>
				<Text 
					style={{textAlign: "center", 
						backgroundColor: "#DFD6D1", 
						paddingTop: 10, 
						paddingBottom: 10
					}} 
					onPress={this._onPress}>
					获取地理位置
				</Text>
			</View>
		);
	}
}